<template>
	<view>
		<button @click="loginUser">登录</button>
	</view>
</template>

<script>
	import {wxLoginApi,getUserInfoApi} from "../../apis/mine.js"
	export default {
		data() {
			return {
				
			};
		},
		methods:{
			loginUser() {
			
				uni.getUserProfile({
					desc: '获取信息',
					success(res) {
						uni.login({
							success(data) {
								const message = {
									code: data.code,
									...res.userInfo,
									appId:'wxc02da419aa262194',
									appSecret:'9ba6f5d31bf97cd0f321e70a4b04e209'
								}
								wxLoginApi(message).then(req => {
									console.log(req);
									uni.setStorageSync("token",req.token);
									getUserInfoApi(req.token).then(val=>{
										console.log(val);
										uni.setStorageSync("userinfo",val[0]);
									})
									uni.showToast({
										title: '标题',
										duration: 2000
									})
									uni.switchTab({
										url: '/pages/index/index'
									})
			
								})
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
